<template>
  <a-modal
    title="撤回任务"
    :visible="visible"
    :confirm-loading="loading"
    width="1000px"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-form-model ref="form" :model="form" :rules="rules">
      <a-form-model-item
        label="撤回说明"
        has-feedback
        :labelCol="{span: 5}"
        :wrapperCol="{span: 15}"
        prop="comment"
      >
        <a-textarea
          placeholder="请填写撤回说明"
          class="custom"
          v-model="form.comment"
          allow-clear
        />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
<script>

import { mapGetters } from 'vuex'

export default {
  name: 'WithdrawTask',
  components: {},
  props: {
    // eslint-disable-next-line vue/require-default-prop
    taskNode: {
      type: Object,
      require: true
    },
    submitType: {
      type: String,
      default: undefined
    }
  },
  data () {
    return {
      // 展示弹框
      visible: false,
      loading: false,
      form: {
        comment: undefined,
        targetKey: undefined,
        assignee: undefined,
        isEndNode: undefined,
        multiInstance: undefined,
        bizId: undefined,
        instanceId: undefined,
        taskId: undefined,
        userId: undefined,
        submitType: undefined
      },
      rules: {
        comment: [{ required: true, message: '撤回说明不能为空', trigger: 'blur' }]
      }
    }
  },
  watch: {
    taskNode: function (val) {
      if (!!val && !!this.submitType && this.submitType === 'C') {
        this.form.taskId = val.taskId
        this.form.bizId = val.bizId
        this.form.instanceId = val.instanceId
      }
    }
  },
  computed: {
    ...mapGetters(['userId'])
  },
  methods: {
    // 确定
    handleOk () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$emit('submitOk', this.form)
        }
      })
    },
    /** 隐藏弹框**/
    handleCancel () {
      this.visible = false
    },
    /** 显示弹框**/
    show () {
      this.visible = true
      this.form = {
        comment: undefined,
        targetKey: undefined,
        assignee: undefined,
        isEndNode: undefined,
        multiInstance: undefined,
        bizId: this.taskNode.bizId,
        instanceId: this.taskNode.instanceId,
        taskId: this.taskNode.taskId,
        userId: this.userId,
        submitType: 'W'
      }
    }
  },
  created () {
  },
  mounted () {
  }
}
</script>,
